<template>
  <basic-container>
    <div v-show="showSearchFlag" class="flex-start m-t-20 m-b-10">
      <div class="flex-center">
        <el-input v-model="search.clientName" class="m-r-10" placeholder="请输入客户名称或手机号" size="small" @keyup.native.enter="query"
                  style="width: 300px;">
          <el-button slot="append" :loading="loading" icon="el-icon-search" size="small" type="primary" @click="query">
            查询
          </el-button>
        </el-input>
      </div>
    </div>
    <div class="flex-center m-b-10">
      <div></div>
      <div class="flex-center">
        <el-button :loading="loading" circle icon="el-icon-refresh" @click="query"></el-button>
        <el-button circle icon="el-icon-search" @click="showSearchFlag=!showSearchFlag"></el-button>
      </div>
    </div>
    <el-table v-loading="loading" :data="data" :header-cell-style="{background:'#eee',color:'#000'}" border
              class="my-table"
              style="width: 100%">
      <el-table-column align="center" label="序号" type="index" width="60"/>
      <el-table-column label="客户名称" min-width="100">
        <template v-slot="scope">{{ scope.row.clientName | defaultValue }}</template>
      </el-table-column>
      <el-table-column label="注册手机" width="100">
        <template v-slot="scope">{{ scope.row.regPhone | defaultValue }}</template>
      </el-table-column>
      <el-table-column label="注册日期" min-width="100">
        <template v-slot="scope">{{ scope.row.createTime | defaultValue }}</template>
      </el-table-column>
      <el-table-column label="系统版本" min-width="100">
        <template v-slot="scope">{{ scope.row.vipLevel | defaultValue }}</template>
      </el-table-column>
      <el-table-column label="到期日期" min-width="100">
        <template v-slot="scope">{{ scope.row.expireDate | defaultValue }}</template>
      </el-table-column>
      <el-table-column label="最近续费日期" min-width="150">
        <template v-slot="scope">{{ scope.row.lastPayTime | defaultValue }}</template>
      </el-table-column>
      <el-table-column label="最近续费金额" min-width="150">
        <template v-slot="scope">{{ scope.row.lastPayMoney | defaultValue }}</template>
      </el-table-column>
      <el-table-column label="设备数量" min-width="100">
        <template v-slot="scope">
          <el-button v-if="scope.row.machineNum" type="text" @click="showBindMac(scope.row)">{{scope.row.machineNum}}
          </el-button >
          <span v-else>{{defaultValue}}</span>
        </template>
      </el-table-column>
<!--      <el-table-column label="操作" width="150">-->
<!--        <template v-slot="scope">-->
<!--          <el-button icon="el-icon-edit" size="small" type="text" @click="toDetail(scope.row)">编辑</el-button>-->

<!--        </template>-->
<!--      </el-table-column>-->
    </el-table>
    <el-dialog :visible.sync="showAddFlag" append-to-body title="设备" width="900px">
      <el-table v-loading="loading" :data="data" :header-cell-style="{background:'#eee',color:'#000'}" border
                class="my-table"
                style="width: 100%"
                @select="handleSelect"
                ref="macMultipleTable"
      >
        <el-table-column align="center" label="序号" type="index" width="60"/>
        <el-table-column label="设备类型" prop="price">
          <template v-slot="scope">{{ scope.row.name | defaultValue }}</template>
        </el-table-column>
        <el-table-column label="主板号">
          <template v-slot="scope">{{ scope.row.contactName | defaultValue }}</template>
        </el-table-column>
        <el-table-column label="绑定时间" width="200">
          <template v-slot="scope">{{ scope.row.contactName | defaultValue }}</template>
        </el-table-column>
      </el-table>
      <app-pagination :page-size="page.size" :total="total" class="m-t-20" @change="pageChange"/>
      <div class="dividing-line m-t-20 m-b-20"></div>
      <div class="flex-end">
        <el-button size="small" type="primary" @click="closeAddAndEdit">关闭</el-button>
      </div>
    </el-dialog>
    <app-pagination ref="paginationRef" :page-size="page.size" :total="total" class="m-t-20" @change="pageChange"/>
    <div class="h-100px"></div>
  </basic-container>
</template>

<script>
import AppPagination from "@/components/business/app-pagination";
import {
  equals,
  getRecords,
  getTotal,
  isListEmpty,
  isStringEmpty,
  msgError,
  isTrue,
  confirmWarning, msgSuccess
} from "@/util/common-util";
import AuthWrapper from "@/components/business/auth-wrapper";
import request from "@/router/axios";
import {deleteRecord} from "@/api/business/filling-team";
import SearchProduct from "@/components/SearchCondition/SearchProduct";
import SearchProductGroup from "@/components/SearchCondition/SearchProductGroup";
import AppFileUpload from "@/components/business/app-file-upload";
import SearchProductType from "@/components/SearchCondition/SearchProductType";
import SearchStatus from "@/components/SearchCondition/SearchStatus";
import {getIotProductList, getList} from "@/api/product/product";
import {facclientPage} from "@/api/product/client";



export default {
  name: "ProductList",
  components: {
    SearchStatus,
    SearchProductType, AppFileUpload, SearchProductGroup, SearchProduct, AuthWrapper, AppPagination},
  data() {
    return {
      page: {
        size: 20,
        current: 1
      },
      total: 0,
      searchDate: '',
      search: {
        clientName: '',
      },
      form: {
        name: '',
        contactName: '',
        contactPhone: '',
        baseUrl: '',
        authToken: ''
      },
      showSearchFlag: true,
      loading: false,
      data: [{}],
      showAddFlag: false,
      submitLoading: false,
      isEdit: false,
    }
  },
  mounted() {
    this.query()
  },
  methods: {
    showBindMac(row) {
      this.showAddFlag = true
    },
    handleUpload() {

    },
    pageChange(_page) {
      this.page = _page
      this.query()
    },
    refresh() {
      this.$refs.paginationRef.reset()
    },
    query() {
      this.loading = true
      facclientPage({...this.page, ...this.search}).then(res => {
        this.data = getRecords(res)
        this.total = getTotal(res)
        this.loading = false
      }).catch(() => {
        this.loading = false
      })
    },
    addNew() {
      this.showAddFlag = true
    },
    toDetail(row) {
      this.$emit('detail', row)
    },
    closeAddAndEdit() {
      this.showAddFlag = false
      this.form.name = ''
      this.form.contactName = ''
      this.form.contactPhone = ''
      this.form.baseUrl = ''
      this.form.authToken = ''
      this.form.id = null
      this.isEdit = false
    },
  }
}
</script>

<style lang="scss" scoped>
.my-table {
  /deep/ .el-button--small {
    padding: 0 5px !important;
    font-size: 14px !important;
  }

  /deep/ td {
    padding: 8px 0 !important;
  }
}
</style>
